package com.hs.shirodemo01.advice;

import com.hs.shirodemo01.exception.ProjectException;
import com.hs.shirodemo01.utils.Constant;
import com.hs.shirodemo01.utils.Result;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName ProjectExpectionAdvice
 * @Description TODO
 * @Author 郭敖
 * @Date 2023年08月18日 21:18
 * @Version 1.0
 */
@RestControllerAdvice
public class ProjectExpectionAdvice {

    /**
     * 统一处理业务异常
     * @param e
     * @return com.hs.shirodemo01.utils.Result
     */
    @ExceptionHandler(ProjectException.class)
    public Result handleException(ProjectException e){
        return new Result(e.getCode(),e.getMessage(),null);
    }

    @ExceptionHandler(AuthorizationException.class)
    public Result handleAuthorizationException(AuthorizationException e){
        return new Result(Constant.FORBIDDEN.getCode(),Constant.FORBIDDEN.getMsg(),null);
    }
}
